{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'name': '贾母', 'category': '第一代'}]\n"
     ]
    },
    {
     "ename": "NameError",
     "evalue": "name 'Graph' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-3-e79e589b24f3>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[0msi\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_dict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0morient\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'records'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msi\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 5\u001b[1;33m graph=Graph(init_opts=opts.InitOpts(\n\u001b[0m\u001b[0;32m      6\u001b[0m   \u001b[0mwidth\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'750px'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mheight\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'700px'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mpage_title\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'关系图'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      7\u001b[0m  ))\n",
      "\u001b[1;31mNameError\u001b[0m: name 'Graph' is not defined"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "df= pd.read_excel('关系图.xlsx')\n",
    "si = df.to_dict(orient='records')\n",
    "print(si)\n",
    "graph=Graph(init_opts=opts.InitOpts(\n",
    "  width='750px',height='700px',page_title='关系图'\n",
    " ))\n",
    "graph.add(series_name='',nodes=list_nodes,links=list_links,\n",
    "         categories=list_categorys,repulsion=8000,\n",
    "         edge_label=opts.LabelOpts(\n",
    "         position='middle',formatter='{b} {c}'))\n",
    "graph.set_global_opts(\n",
    "title_opts=opts.TitleOpts(\n",
    "title='红楼梦中的人物关系图',pos_left='center'),\n",
    "legend_opts=opts.LegendOpts(\n",
    "pos_top='80%',pos_right='1%',orient='vertical'))\n",
    "graph.render('例8-3.html')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
